<?php
/**
 * Event Types  Controller class
 * @author 		TAMDV
 * @date		2008 07 21 (yyyy MM dd)
 * @package    	Joomus.JBS
 * @subpackage 	Components
 * @link 		http://localhost/jbschedule/administrator/index.php?option=com_jbschedule
 * @license		GNU/GPL
 */
jimport('joomla.application.component.controller');
// no direct access
//defined('_JEXEC') or die('Restricted access');

class JBSControllerRoles extends JController {
	/**
 	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();

		// Register Extra tasks
		$this->registerTask( 'add'  , 	'edit' );
	}

	function display()
	{
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $VIEW_ROLES, 'index.php?option=com_jbschedule', JText :: _('VIEW ROLES').' - '.JText :: _('NO PERMISSION'))){
			return;
		}
		JRequest::setVar( 'view', 'roles' );
		JRequest::setVar( 'layout', 'list'  );
		parent::display();
	}

	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
		if ($this->getTask() === 'add') {
			if (!JBSRoles :: checkPermission($this, JBSConfig :: $ADD_ROLES, 'index.php?option=com_jbschedule&controller=roles', JText :: _('ADD NEW ROLES').' - '.JText :: _('NO PERMISSION')))
				return;
		}
		else if ($this->getTask() === 'edit') {
			if (!JBSRoles :: checkPermission($this, JBSConfig :: $EDIT_ROLES, 'index.php?option=com_jbschedule&controller=roles', JText :: _('EDIT ROLES').' - '.JText :: _('NO PERMISSION')))
				return;
		}

		JRequest::setVar( 'view', 'roles' );
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
		$model = $this->getModel('roles');
		if ($model->store($post)) {
			$msg = JText::_( 'SAVED' );
		} else {
			$msg = JText::_( 'NOT SAVED' );
		}

		// Check the table in so it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_jbschedule&controller=roles';
		$this->setRedirect($link, $msg);
	}

	/**
	 * remove record(s)
	 * @return void
	 */
	function remove()
	{
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $DEL_ROLES, 'index.php?option=com_jbschedule&controller=roles', JText :: _('DELETE ROLES').' - '.JText :: _('NO PERMISSION')))
			return;

		$model = $this->getModel('roles');

		if (!$model->delete()) {
			$msg = JText :: _('NOT DELETED');
		} else {
			$msg = JText :: _('DELETED');
		}

		$this->setRedirect( 'index.php?option=com_jbschedule&controller=roles', $msg );
	}

	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel()
	{
		$msg = JText :: _('CANCELED');
		$this->setRedirect( 'index.php?option=com_jbschedule&controller=roles', $msg );
	}
}

?>